package com.canaan.business.controller.pc.storehouse;

import java.util.List;

import com.canaan.business.domain.vo.CheckReviewVo;
import com.canaan.business.domain.vo.StockCheckPdaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.storehouse.StockCheck;
import com.canaan.business.service.storehouse.IStockCheckService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 库存盘点任务Controller
 *
 * @author ruoyi
 * @date 2023-02-14
 */
@Api(tags = "库存盘点任务")
@RestController
@RequestMapping("/storehouse/stockCheck")
public class StockCheckController extends BaseController {
    @Resource
    private IStockCheckService stockCheckService;

    /**
     * 查询库存盘点任务列表
     */
    @ApiOperation(value = "查询库存盘点任务列表")
    @GetMapping("/list")
    public TableDataInfo list(StockCheck stockCheck) {
        startPage();
        List<StockCheck> list = stockCheckService.selectStockCheckList(stockCheck);
        return getDataTable(list);
    }


    /**
     * 查询库存盘点任务列表
     */
    @ApiOperation(value = "查询库存盘点任务列表")
    @GetMapping("/listPda")
    public TableDataInfo listPda(StockCheckPdaVo stockCheck) {
        startPage();
        List<StockCheckPdaVo> list = stockCheckService.listPda(stockCheck);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点任务列表
     */
    @ApiOperation(value = "导出库存盘点任务列表")
    @Log(title = "库存盘点任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockCheck stockCheck) {
        List<StockCheck> list = stockCheckService.selectStockCheckList(stockCheck);
        ExcelUtil<StockCheck> util = new ExcelUtil<StockCheck>(StockCheck.class);
        util.exportExcel(response, list, "库存盘点任务数据");
    }

    /**
     * 获取库存盘点任务详细信息
     */
    @ApiOperation(value = "获取库存盘点任务详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockCheckService.selectStockCheckById(id));
    }

    /**
     * 新增库存盘点任务
     */
    @ApiOperation(value = "新增库存盘点任务")
    @Log(title = "库存盘点任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.insertStockCheck(stockCheck));
    }

    /**
     * 修改库存盘点任务
     */
    @ApiOperation(value = "修改库存盘点任务")
    @Log(title = "库存盘点任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.updateStockCheck(stockCheck));
    }

    /**
     * 删除库存盘点任务
     */
    @ApiOperation(value = "删除库存盘点任务")
    @Log(title = "库存盘点任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockCheckService.deleteStockCheckByIds(ids));
    }

    /**
     * 开始盘点任务
     */
    @ApiOperation(value = "开始盘点任务")
    @Log(title = "开始盘点任务", businessType = BusinessType.UPDATE)
    @PostMapping("/startCheck/{ids}")
    public AjaxResult startCheck(@PathVariable Long[] ids){
            return toAjax(stockCheckService.startCheck(ids));
    }
    /**
     * 创建复盘任务
     */
    @ApiOperation(value = "创建复盘任务")
    @Log(title = "创建复盘任务", businessType = BusinessType.INSERT)
    @PostMapping("/createReCheck/{ids}")
    public AjaxResult createReCheck(@PathVariable Long[] ids) {
        return toAjax(stockCheckService.createReCheck(ids));
    }

    /**
     * 取消盘点任务
     */
    @ApiOperation(value = "取消盘点任务")
    @Log(title = "取消盘点任务", businessType = BusinessType.CLEAN)
    @PostMapping("/cancelCheck/{ids}")
    public AjaxResult cancelCheck(@PathVariable Long[] ids){
        return toAjax(stockCheckService.cancelCheck(ids));
    }
    /**
     * 提交差异审核
     */
    @ApiOperation(value = "提交差异审核")
    @Log(title = "提交差异审核", businessType = BusinessType.UPDATE)
    @PostMapping("/submitReview/{id}")
    public AjaxResult submitReview(@PathVariable Long id){
        return toAjax(stockCheckService.submitReview(id));
    }
    /**
     * 通过差异审核
     */
    @ApiOperation(value = "通过差异审核")
    @Log(title = "通过差异审核", businessType = BusinessType.UPDATE)
    @PostMapping("/reviewPass")
    public AjaxResult reviewPass(@RequestBody CheckReviewVo vo){
        return toAjax(stockCheckService.reviewPass(vo));
    }
    /**
     * 拒绝差异审核
     */
    @ApiOperation(value = "拒绝差异审核")
    @Log(title = "拒绝差异审核", businessType = BusinessType.UPDATE)
    @PostMapping("/reviewFail")
    public AjaxResult reviewFail(@RequestBody CheckReviewVo vo){
        return toAjax(stockCheckService.reviewFail(vo));
    }
    /**
     * 结束盘点任务
     */
    @ApiOperation(value = "结束盘点任务")
    @Log(title = "结束盘点任务", businessType = BusinessType.INSERT)
    @PostMapping("/finish/{ids}")
    public AjaxResult finish(@PathVariable Long[] ids) {
        return toAjax(stockCheckService.finish(ids));
    }


    /**
     * 结束盘点任务,直接复盘
     */
    @ApiOperation(value = "结束盘点任务,直接复盘")
    @Log(title = "结束盘点任务,直接复盘", businessType = BusinessType.INSERT)
    @PostMapping("/createReCheckDirect/{ids}")
    public AjaxResult createReCheckDirect(@PathVariable Long[] ids) {
        return toAjax(stockCheckService.createReCheckDirect(ids));
    }

    /**
     * 分配库存盘点任务
     */
    @ApiOperation(value = "分配库存盘点任务")
    @Log(title = "分配库存盘点任务", businessType = BusinessType.UPDATE)
    @PutMapping("/allocation")
    public AjaxResult allocation(@RequestBody StockCheck stockCheck) {
        return toAjax(stockCheckService.allocation(stockCheck));
    }


    /**
     * 获取库存盘点任务详细信息
     */
    @ApiOperation(value = "获取库存盘点任务详细信息")
    @GetMapping(value = "/getDetail/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id) {
        return success(stockCheckService.getDetail(id));
    }
}
